import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class MainTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public void insert() throws IOException{
        String driver = "com.mysql.jdbc.Driver"; 
        String url = "jdbc:mysql://localhost:3306/dbtest"; 
        String user = "root"; 
        String password = "123456"; 
        try { 
             Class.forName(driver); 
             Connection conn = DriverManager.getConnection(url, user, password);
 
             if(!conn.isClosed()) 
                  System.out.println("CONNECTED"); 
             Statement stmt = conn.createStatement();
             String base = "./dataGen1/";
             BufferedReader br = new BufferedReader(new FileReader(base+"student_inf.data"));
             int cnt = 0;
             cnt = Integer.parseInt(br.readLine());
             System.out.println("A "+cnt );
             while(cnt>0){
            	 String line = br.readLine();
            	 if(line==null) break;
                 String query = "INSERT INTO student_inf VALUES ("+line+")";
                 stmt.execute(query);
                 
                 cnt--;
             }
             System.out.println("A "+cnt );
             br = new BufferedReader(new FileReader(base+"course_teacher.data"));
             cnt = Integer.parseInt(br.readLine());
             System.out.println("A "+cnt );
             while(cnt>0){
            	 String line = br.readLine();
            	 if(line==null) break;
                 String query = "INSERT INTO course_teacher VALUES ("+line+")";
                 stmt.execute(query);
                 
                 cnt--;
             }
             System.out.println("A "+cnt );
             br = new BufferedReader(new FileReader(base+"student_course.data"));
             cnt = Integer.parseInt(br.readLine());
             System.out.println("A "+cnt );
             while(cnt>0){
            	 String line = br.readLine();
            	 if(line==null) break;
                 String query = "INSERT INTO student_course VALUES ("+line+")";
                 stmt.execute(query);
                 
                 cnt--;
             }
             System.out.println("A "+cnt );
             br.close();
             conn.close(); 
        } 
        catch(ClassNotFoundException e) { 
             e.printStackTrace(); 
        } 
        catch(SQLException e) { 
             e.printStackTrace(); 
        } 		
	}
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		MainTest mt = new MainTest();
		mt.insert();
	}

}
